package com.byx.chatserver.controller;

import com.byx.chatserver.entity.Friend;
import com.byx.chatserver.entity.SimpleFriend;
import com.byx.chatserver.service.IFriendService;
import com.byx.chatserver.vo.FriendParam;
import com.byx.springboot.unifiedresponseresult.entity.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * FriendController
 *
 * @author Superb
 * @date 2021/4/30 23:12
 */
@RestController
@ResponseResult
@RequestMapping("/friend")
public class FriendController {
    private IFriendService friendService;

    @Autowired
    public void setFriendService(@Qualifier("friendServiceImpl") IFriendService friendService) {
        this.friendService = friendService;
    }

    /**
     * 加好友接口
     * 测试通过
     * @param friendParam 必要的参数：userLoginId 用户账号,friendLoginId 对方账号,
     *                    remark 用户给对方加的备注,friendGroupId 用户分配的对方分组id,
     *                    对方给用户的备注默认为用户昵称,分组id默认使用最小的id，即用户最先创建的分组
     */
    @PostMapping("/add")
    public void addFriend(@RequestBody FriendParam friendParam){
        friendService.addFriend(friendParam);
    }

    @PostMapping("/delete")
    public void deleteFriend(@RequestParam("userId") Long userId,@RequestParam("friendId") Long friendId){
        friendService.deleteFriend(userId,friendId);
    }

    @GetMapping("/queryFriends/{id}")
    public List<SimpleFriend> queryFriends(@PathVariable("id") Long id){
        return friendService.getAllFriends(id);
    }

    @GetMapping("/queryFriendDetailInfo/{userId}/{friendId}")
    public Friend queryFriendDetailInfo(@PathVariable Long userId, @PathVariable Long friendId){
        return friendService.getFriendDetailInfo(userId,friendId);
    }

    @GetMapping("/queryFriendDetailInfoByLoginId/{userId}/{friendId}")
    public Friend queryFriendDetailInfoByLoginId(@PathVariable Long userId, @PathVariable String friendId){
        return friendService.getFriendDetailInfoByLoginId(userId,friendId);
    }

    @PostMapping("/changeFriendRemark")
    public void changeFriendRemark(@RequestParam("userId") Long userId,@RequestParam("friendId") Long friendId,@RequestParam("remark") String remark){
        friendService.changeFriendRemark(userId,friendId,remark);
    }
}
